package com.pactera.madp.cp.controller.oms.workroom;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.workroom.WorkMassMsgDetailsPageDTO;
import com.pactera.madp.cp.api.dto.workroom.WorkMassMsgPageDTO;
import com.pactera.madp.cp.api.vo.workroom.WorkMassMsgDetailsListVO;
import com.pactera.madp.cp.api.vo.workroom.WorkMassMsgDetailsVO;
import com.pactera.madp.cp.api.vo.workroom.WorkMassMsgPageVO;
import com.pactera.madp.cp.service.WorkMassMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;

/**
 * WorkMassMsgController
 *
 * @author jun
 * @version 1.0
 * 2021/7/13 10:43
 **/
@RestController
@RequestMapping("/mass")
@Api(value = "mass",tags = "群发信息")
@AllArgsConstructor
public class WorkMassMsgController {

    private final WorkMassMsgService workMassMsgService;

    @SysLog("同步群发信息")
    @PutMapping("/syn")
    @ApiOperation(value = "同步群发信息")
    public R get(Integer type){
        workMassMsgService.syncGroupMsgList(type);
        return R.ok();
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<List<WorkMassMsgPageVO>>> getPage(Page page, WorkMassMsgPageDTO dto){
        return R.ok(workMassMsgService.getPageList(page,dto));
    }

    @GetMapping("/details")
    @ApiOperation(value = "客户/群详情-基础信息")
    public R<WorkMassMsgDetailsVO> getDetailsByMassId(Integer massId){
        return R.ok(workMassMsgService.getDetailsByMassId(massId));
    }

    @GetMapping("/list")
    @ApiOperation(value = "客户/群详情列表")
    public R<Page<List<WorkMassMsgDetailsListVO>>> getDetailsByMassIdList(WorkMassMsgDetailsPageDTO dto, Page page){
        return R.ok(workMassMsgService.getDetailsByMassIdList(dto,page));
    }

    @SysLog("群发信息-导出Excel")
    @PostMapping("/excel")
    @ApiOperation(value = "导出Excel")
    public void exitExcelList(@RequestBody WorkMassMsgPageDTO dto, HttpServletResponse response, OutputStream out){
        workMassMsgService.exitExcelList(dto,response,out);
    }

}
